import 'package:flutter/services.dart';

class FilePicker {
  // 创建一个静态的私有实例
  static final FilePicker _instance = FilePicker._internal();

  // 通信通道
  static final String _CHANNEL = 'file_picker';

  // Flutter与原生Android代码通信的MethodChannel实例
  static final MethodChannel _channel = MethodChannel(_CHANNEL);

  // 私有构造函数
  FilePicker._internal();

  // 获取单例实例
  static FilePicker get instance => _instance;

  // 获取文件uri
  static Future<void> getFileUri() async {
    try {
      await _channel.invokeMethod('getFileUri');
    } on PlatformException catch (e) {
      print("打开文件选择器失败: ${e.message}");
    }
  }

  // 选择文件夹（用于录音输出）
  static Future<String?> getFolderUri() async {
    try {
      final String? uri = await _channel.invokeMethod('getFolderUri');
      return uri;
    } on PlatformException catch (e) {
      print("选择文件夹时出错: ${e.message}");
      return null;
    }
  }
}
